package com.whoiszxl.event;

import com.whoiszxl.core.constants.RocketMQConstant;
import com.whoiszxl.events.MemberDomainEventPublisher;
import com.whoiszxl.events.MemberLoginSuccessEvent;
import com.whoiszxl.mq.RocketMQProducer;
import lombok.RequiredArgsConstructor;
import net.dreamlu.mica.core.utils.JsonUtil;
import org.springframework.stereotype.Component;

/**
 * 领域事件发布服务实现
 *
 * @author whoiszxl
 * @date 2022/1/24
 */
@Component
@RequiredArgsConstructor
public class MemberDomainEventPublisherImpl implements MemberDomainEventPublisher {

    private final RocketMQProducer rocketMQProducer;

    @Override
    public void publishMemberLoginSuccessEvent(MemberLoginSuccessEvent memberLoginSuccessEvent) {
        String message = JsonUtil.toJson(memberLoginSuccessEvent);
        rocketMQProducer.sendMessage(RocketMQConstant.MEMBER_LOGIN_TOPIC, message, "用户登录成功的领域事件");
    }

}
